package com.ecloud.hbase.entities;

import com.alibaba.fastjson.JSON;
import com.ecloud.common.ResultEnum;
import com.ecloud.common.exception.ServerException;
import com.ecloud.hbase.standard.HbaseTable;
import com.ecloud.trend.vo.TdbPresentVo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * tdb实时数据 hbase表类接口
 *
 * @author Squbi
 */

public interface TdbPresentHbaseTable extends HbaseTable {
    /**
     * 获取时间/数据映射表
     *
     * @return Map
     * @author Squbi
     * @date 2021/7/26 17:50
     */
    Map<String, String> getBuildingMap();

    /**
     * 设置时间/数据映射表
     *
     * @param map map
     * @author Squbi
     * @date 2021/7/26 17:56
     */
    void setBuildingMap(Map<String, String> map);

    /**
     * 转换{@link TdbPresentHbaseTable}到Map`String,List< TdbPresentVo>`
     *
     * @return map
     * @author Squbi
     * @date 2021/7/27 9:21
     */
    default Map<String, List<TdbPresentVo>> toPresentMapping() {
        Map<String, String> map = getBuildingMap();
        if (map == null || map.isEmpty()) {
            throw new ServerException(ResultEnum.REQUEST_NULL);
        }
        Map<String, List<TdbPresentVo>> result = new HashMap<>();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            List<TdbPresentVo> tdbPresentVos = JSON.parseArray(entry.getValue(), TdbPresentVo.class);
            result.put(entry.getKey(), tdbPresentVos);
        }
        return result;
    }
}
